package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.content.mapper.CourseTeacherMapper;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseTeacherServiceImpl implements CourseTeacherService {

    @Autowired
    CourseTeacherMapper courseTeacherMapper;

    @Override
    public List<CourseTeacher> getcourseTeacher(Long courseId) {
    //根据课程id查询教师信息
        LambdaQueryWrapper<CourseTeacher> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CourseTeacher::getCourseId,courseId);
        return courseTeacherMapper.selectList(queryWrapper);
    }

    @Override
    public CourseTeacher addAndupdatecourseTeacher(CourseTeacher courseTeacher) {
        //判断是新增还是修改
        if(courseTeacher.getId()==null){
            //新增
            courseTeacher.setCreateDate(LocalDateTime.now());
            courseTeacherMapper.insert(courseTeacher);
        }else {
            //修改
            courseTeacher.setCreateDate(LocalDateTime.now());
            courseTeacherMapper.updateById(courseTeacher);
        }
        return courseTeacher;
    }

    @Override
    public void deletecourseTeacher(Long courseId, Long id) {
        //根据教师id删除教师信息
        courseTeacherMapper.deleteById(id);
    }
}
